package common;

import java.io.FileReader;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

public class JdbcConnectionFactory {
	private static String dbUrl;

	private static String dbDriver;

	private static String user;

	private static String password;
	static {
		try {
			Properties pro = new Properties();
			//2. 加载文件
			pro.load(new FileReader("jdbc.properties"));
			dbUrl = pro.getProperty("url");
			dbDriver = pro.getProperty("driver");
			user = pro.getProperty("user");
			password = pro.getProperty("password");
/*			dbUrl="jdbc:mysql://localhost:3306/db3?serverTimezone=UTC&useSSL=true&useUnicode=true&characterEncoding=UTF-8";
			dbDriver="com.mysql.cj.jdbc.Driver";
			user="root";
			password="123456";*/
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public static Connection getConnection() {
		Connection con = null;
		try {
			Class.forName(dbDriver);
			con = DriverManager.getConnection(dbUrl, user, password);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return con;
	}
}
